package cn.sciento.onelink.sim.combo.purchasable.offering;

import cn.sciento.onelink.CommonResponse;
import cn.sciento.onelink.LinkRequest;
import cn.sciento.onelink.exception.RequestException;
import cn.sciento.onelink.utils.TransIdUtil;
import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.HashMap;

/**
 * 可订购资费实时查询
 * @author walton
 */
@Data
@Builder
public class SimPurchasableOfferingRequest extends LinkRequest<CommonResponse<SimPurchasableOfferingResult>> {
    private String appId;
    private String token;
    private String queryType;
    private String groupId;
    private String msisdn;
    private String pageSize;
    private String startNum;
    private String catalogId;
    private String categoryId;

    public SimPurchasableOfferingRequest(String appId, String token, String queryType, String groupId, String msisdn, String pageSize, String startNum, String catalogId, String categoryId) {
        super(LinkRequest.Method.GET);
        this.appId = appId;
        this.token = token;
        this.queryType = queryType;
        this.groupId = groupId;
        this.msisdn = msisdn;
        this.pageSize = pageSize;
        this.startNum = startNum;
        this.catalogId = catalogId;
        this.categoryId = categoryId;
        this.path = "/ec/query/purchasable-offerings";
        HashMap<String, Object> heahMap = new HashMap<String, Object>();
        this.setHeader(heahMap);
        HashMap<String, Object> bodyMap = new HashMap<String, Object>();
        bodyMap.put("transid", TransIdUtil.generate(appId));
        bodyMap.put("token", token);
        bodyMap.put("pageSize", pageSize);
        bodyMap.put("startNum", startNum);
        bodyMap.put("catalogId", catalogId);
        bodyMap.put("categoryId", categoryId);
        if (StringUtils.isNotEmpty(queryType) && queryType.equals("1")) {
            bodyMap.put("queryType", queryType);
        } else if (StringUtils.isNotEmpty(groupId) && StringUtils.isNotEmpty(queryType) && queryType.equals("2")) {
            bodyMap.put("queryType", queryType);
            bodyMap.put("groupId", groupId);
        }else if (StringUtils.isNotEmpty(msisdn) && StringUtils.isNotEmpty(queryType) && queryType.equals("3")) {
            bodyMap.put("queryType", queryType);
            bodyMap.put("msisdn", msisdn);
        }else {
            throw new RuntimeException(new RequestException("queryType/groupId/msisdn输入有误，请重新输入"));
        }
        this.setCompleteUrl(this.path,bodyMap);
    }
}